package model.forview;

import java.util.ArrayList;

import model.wrap.node.Node;
import model.wrap.structure.Structure;
import models.ConstantName;
import models.ConstantValue;

public class NodeModelForView extends ContentForMainTemplate
{
    public ArrayList<Node> parents;
    public ArrayList<Node> child;

    public String typeTitle;
    public String structureTitle;
    public String title;
    public Long idNode;
    public Long idStructure;
    
    public Node node;

    public NodeModelForView(Node node)
    {
	fillField(node);
	setDefaultValues();
    }

    public NodeModelForView(Long id)
    {
	fillField(new Node(id));
	setDefaultValues();
    }
    
    public NodeModelForView(Structure str)
    {
	this.parents = new ArrayList<Node>();
	this.child = Node.getRootNodes(str);
	this.typeTitle = "";
	this.structureTitle = str.getTitle();
	this.title = "Вершина структуры.";
	this.idNode = new Long(0);
	this.idStructure = str.getId();
	setDefaultValues();
    }

    private void fillField(Node node)
    {
	this.idStructure = node.getStructure().getId();
	parents = new ArrayList<Node>();
	ArrayList<Node> pNode = node.getParents();
	for (Node node2 : pNode)
	{
	    parents.add(node2);
	}
	child = new ArrayList<Node>();
	ArrayList<Node> cNode = node.getChildren();
	for (Node node2 : cNode)
	{
	    child.add(node2);
	}
	typeTitle = node.getType().getTitle();
	structureTitle = node.getStructure().getTitle();
	idNode = node.getId();
	title = node.getTitle();
	this.node = node;
    }

    private void setDefaultValues()
    {
	String title = ConstantValue.getConstantValue(ConstantName.NODE_CREATE_PAGE_TITLE);
	String header = ConstantValue.getConstantValue(ConstantName.NODE_CREATE_PAGE_HEADER);
	String footer = ConstantValue.getConstantValue(ConstantName.NODE_CREATE_PAGE_FOOTER);
	String userName = "";

	title = title != null ? title : "Узел";
	header = header != null ? header : "Просмотр информации узла";
	footer = footer != null ? footer : "Просмотр информации узла";

	mainModelForView = new MainModelForView(title, userName, header, footer);
    }
}
